package com.office.forum.manage.likePosts.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.forum.manage.likePosts.domain.ForumFavoritePosts;
import com.office.forum.manage.likePosts.service.IForumFavoritePostsService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 用户收藏帖子记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-05
 */
@RestController
@RequestMapping("/forum/likePosts")
public class ForumFavoritePostsController extends BaseController
{
    @Autowired
    private IForumFavoritePostsService forumFavoritePostsService;

    /**
     * 查询用户收藏帖子记录列表
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumFavoritePosts forumFavoritePosts)
    {
        startPage();
        List<ForumFavoritePosts> list = forumFavoritePostsService.selectForumFavoritePostsList(forumFavoritePosts);
        return getDataTable(list);
    }

    /**
     * 导出用户收藏帖子记录列表
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:export')")
    @Log(title = "用户收藏帖子记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumFavoritePosts forumFavoritePosts)
    {
        List<ForumFavoritePosts> list = forumFavoritePostsService.selectForumFavoritePostsList(forumFavoritePosts);
        ExcelUtil<ForumFavoritePosts> util = new ExcelUtil<ForumFavoritePosts>(ForumFavoritePosts.class);
        util.exportExcel(response, list, "用户收藏帖子记录数据");
    }

    /**
     * 获取用户收藏帖子记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:query')")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(forumFavoritePostsService.selectForumFavoritePostsByFavoriteId(favoriteId));
    }

    /**
     * 新增用户收藏帖子记录
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:add')")
    @Log(title = "用户收藏帖子记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumFavoritePosts forumFavoritePosts)
    {
        return toAjax(forumFavoritePostsService.insertForumFavoritePosts(forumFavoritePosts));
    }

    /**
     * 修改用户收藏帖子记录
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:edit')")
    @Log(title = "用户收藏帖子记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumFavoritePosts forumFavoritePosts)
    {
        return toAjax(forumFavoritePostsService.updateForumFavoritePosts(forumFavoritePosts));
    }

    /**
     * 删除用户收藏帖子记录
     */
    @PreAuthorize("@ss.hasPermi('forum:likePosts:remove')")
    @Log(title = "用户收藏帖子记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(forumFavoritePostsService.deleteForumFavoritePostsByFavoriteIds(favoriteIds));
    }
}
